﻿using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using EcoSystem.Permissions;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Volo.Abp;
using Volo.Abp.Application.Dtos;

namespace EcoSystem;

/// <summary>
/// 通用报表管理
/// </summary>
[Area(EcoSystemRemoteServiceConsts.ModuleName)]
[RemoteService(Name = EcoSystemRemoteServiceConsts.RemoteServiceName)]
[Route("api/Platform/reportConfig")]
public class ReportConfigController : EcoSystemController, IReportConfigAppService
{
    private readonly IReportConfigAppService _service;

    public ReportConfigController(IReportConfigAppService service)
    {
        _service = service;
    }

    /// <summary>
    /// 创建
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpPost]
    public async Task<ReportConfigDto> CreateAsync([JsonBinder] CreateOrUpdateReportConfigDto input)
    {
        return await _service.CreateAsync(input);
    }

    /// <summary>
    /// 获取详情
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>
    [HttpGet]
    [Route("{id}")]
    public async Task<ReportConfigDto> GetAsync(Guid id)
    {
        return await _service.GetAsync(id);
    }

    /// <summary>
    /// 修改
    /// </summary>
    /// <param name="id"></param>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpPut]
    [Route("{id}")]
    public async Task<ReportConfigDto> UpdateAsync(Guid id, [JsonBinder] CreateOrUpdateReportConfigDto input)
    {
        return await _service.UpdateAsync(id, input);
    }

    /// <summary>
    /// 列表查询
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpGet]
    public async Task<PagedResultDto<ReportConfigDto>> GetListAsync(GetReportConfigInput input)
    {
        return await _service.GetListAsync(input);
    }

    /// <summary>
    /// 获取所有
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpGet]
    [Route("all")]
    public async Task<ListResultDto<ReportConfigDto>> GetAllAsync(GetReportConfigInput input)
    {
        return await _service.GetAllAsync(input);
    }

    /// <summary>
    /// 查询拥有的列表
    /// </summary>
    /// <param name="onlyEnabled"></param>
    /// <returns></returns>
    [HttpGet]
    [Route("owns/list")]
    public async Task<ListResultDto<ReportConfigDto>> GetOwnsListAsync(bool onlyEnabled = true)
    {
        return await _service.GetOwnsListAsync(onlyEnabled);
    }

    /// <summary>
    /// 获取配置
    /// </summary>
    /// <param name="code"></param>
    /// <returns></returns>
    [HttpGet]
    [Route("config/{code}")]
    public async Task<ReportConfigDto> GetForCodeAsync(string code)
    {
        return await _service.GetForCodeAsync(code);
    }

    /// <summary>
    /// 删除
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>
    [HttpDelete]
    [Route("{id}")]
    public async Task DeleteAsync(Guid id)
    {
        await _service.DeleteAsync(id);
    }
}
